package com.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.web.entity.PubNews;
import com.web.entity.SysPoster;
import com.web.entity.SysUser;
import com.web.service.SysPosterService;

@Controller
@RequestMapping("poster")
public class SysPosterController {

	@Autowired
	private SysPosterService sysPosterService;

	@RequestMapping("tap")
	public String Tappage() {
		return "manage/adminPoster";
	}

	@ResponseBody
	@RequestMapping("displayPoster")
	public List<SysPoster> dislplayPoster(Model model) {
		// Map<String, Object> map=new HashMap<String, Object>();
		model.addAttribute("posterList", sysPosterService.selectPoster());
		// map=sysPosterService.selectPoster();
		return sysPosterService.selectPoster();
	}

	@ResponseBody
	@RequestMapping("posterlist")
	private PageInfo<SysPoster> list(SysPoster sp, Integer pageNum, Integer pageSize) {

		return sysPosterService.selectAllPoster(sp, pageNum, pageSize);
	}

	@ResponseBody
	@RequestMapping("getId")
	public List<SysPoster> getId(@RequestParam("id") Integer id) {
		return sysPosterService.getIdPoster(id);
	}

	@ResponseBody
	@RequestMapping("updateState")
	public Map<String, Object> updateState(@RequestParam("id") Integer id, @RequestParam("state") int state) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (state == 1) {
			state = 0;
		} else {
			state = 1;
		}
		// System.out.println(id+" #### "+state);
		map = sysPosterService.changePosterState(id, state);
		return map;
	}

	@ResponseBody
	@RequestMapping("updatePoster")
	public Map<String, Object> updatePoster(@RequestParam("id") Integer id, @RequestParam("state") Integer state,
			@RequestParam("name") String name, @RequestParam("path") String path,
			@RequestParam("remark") String remark) {
		Map<String, Object> map = new HashMap<String, Object>();
		map = sysPosterService.changePoster(id, name, path, state, remark);
		return map;
	}

	@ResponseBody
	@RequestMapping("savePoster")
	public Map<String, Object> save(SysPoster sysPoster) {
		Map<String, Object> map = new HashMap<String, Object>();
		map = sysPosterService.addPoster(sysPoster);
		return map;
	}

	@ResponseBody
	@RequestMapping("delRow")
	public Map<String, Object> delRow(@RequestParam("id") Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map = sysPosterService.delRowPoster(id);
		return map;
	}

}
